<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="icon" href="image/网页图标.png" type="image/x-icon">
  <title>QQ找回密码 - 验证码验证</title>
  <script src="http://47.106.66.89:8080/js/vue.min.js"></script>
  <script src="http://47.106.66.89:8080/js/axios.min.js"></script>
  <link  href="http://47.106.66.89:8080/js/ele-2.15.7/theme-chalk/index.css" rel="stylesheet">
  <script src="http://47.106.66.89:8080/js/ele-2.15.7/index.js"></script>
  <style>
    body {
      font-family: Arial, sans-serif;
      margin: 40px;
      display: flex;
      flex-direction: column;
      align-items: center;
    }

    .form-container {
      width: 300px;
      padding: 20px;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    }

    .form-group {
      margin-bottom: 15px;
    }

    .form-group label {
      display: block;
      margin-bottom: 5px;
    }

    .form-group input {
      width: 100%;
      padding: 8px;
      box-sizing: border-box;
    }

    .button {
      width: 100%;
      padding: 10px;
      background-color: #4CAF50;
      color: white;
      border: none;
      cursor: pointer;
    }

    .button:hover {
      background-color: #45a049;
    }

    .error-message {
      color: red;
      margin-top: 5px;
    }
  </style>
</head>
<body>
<div id="app">
<div class="form-container">
  <h2>QQ找回密码 - 验证码验证</h2>
  <div id="recoverForm">
    <div class="form-group">
      <label for="qqNumber">QQ号码/邮箱/手机号：</label>
      <input type="text" id="qqNumber" name="qqNumber" v-model="email" required>
    </div>
    <div class="form-group">
      <label for="captcha">验证码：</label>
      <input type="text" id="captcha" name="captcha" v-model="pwdemail" required>
      <button type="button" @click="sendCaptcha">发送验证码</button>
      <div class="error-message" id="captchaError"></div>
    </div>
    <div class="form-group" id="newPasswordGroup" style="display: none;"> <!-- 初始隐藏 -->
      <label for="newPassword">请输入新密码：</label>
      <input type="password" id="newPassword" name="newPassword" v-model="pwd1" required>
      <label for="newPassword">再次输入密码：</label>
      <input type="password" id="newPassword1" name="newPassword" v-model="pwd2" required>
      <button @click="updatepwd">确认</button>
    </div>
    <div class="form-group">
      <button type="submit" class="button" @click="submitForm">提交验证</button> <!-- 添加了onclick事件 -->
    </div>
  </div>
</div>
</div>
<script>
  var a = new Vue({
    el: '#app',
    data: {
      email: '',
      remail: '',
      pwdemail: '',
      pwd1: '',
      pwd2: ''
    },
    created() {
    },
    watch: {

    },
    methods: {
      sendCaptcha(){
        //获取邮箱验证码
        const email = this.email; // 将 this.email 的值赋给局部变量 email
        axios.get("http://127.0.0.1/cloud-user/vcode/pwdemail?email="+email+"&title=忘记密码验证邮箱").then(res=>{
          if (res.data.code === 1){
            this.remail = this.email;
            this.$alert("获取验证码成功");
          }
        });
      },
      submitForm(){
        console.info(this.remail);
        axios.get("cloud-user/pwdemail?email="+ this.remail + "&pwdcode=" + this.pwdemail).then(res=>{
          if(res.data.code == 1){
            this.$alert(res.data.msg);
            // 验证码正确，显示新密码输入框
            document.getElementById('newPasswordGroup').style.display = 'block';
            // 禁用提交按钮，防止重复提交（可选）
            document.querySelector('.button').disabled = true;
            // 更改提交按钮的文本（可选）
            document.querySelector('.button').textContent = '设置新密码中...';
          }else{
            this.$alert(res.data.msg);
            document.getElementById('captchaError').textContent = '验证码错误，请重新输入。';
          }
        });
      },
      //更新密码
      updatepwd(){
        if(this.pwd1 == '' || this.pwd2 == ''){
          this.$alert("请输入新密码!");
          return;
        }
        if(this.pwd1 != this.pwd2){
          this.$alert("两次密码输入不一致!");
          return;
        }
        let fd = new URLSearchParams();
        fd.append("email", this.remail);
        fd.append("pwd", this.pwd1);
        axios.post("cloud-user/updatenewpwd", fd).then(res=>{
          if(res.data.code == 1){
            this.$message(res.data.msg + "，将于三秒后跳转登录界面！");
            // 设置三秒定时器
            setTimeout(() => {
              location.href = "login.html"; // 三秒后跳转到登录界面
            }, 3000); // 3000 毫秒等于三秒
          }else{
            this.$alert(res.data.msg);
          }
        });
      }
    }
  });
</script>

</body>
</html>